Is there a type for "any crawler"?
# crawlee-js
n
I have a bunch of different crawler definitions (for different sites) that might use different crawlee crawlers. Site X might use a
PlaywrightCrawler
while site Y uses
CheerioCrawler
. I wrap this logic in a definition like
Copy code
class SiteXCrawlerDefinition {
  getCrawler() { return new PlaywrightCrawler() }
}
since I do want to add an interface to the crawler definition classes I'd need a return type for
getCrawler
.
BasicCrawler
doesn't work - is there another type for "just any crawlee crawler"?
a
message has been deleted
n
Hello, since all Crawlee crawlers inherit via different paths, there isn’t a single “catch-all” type for every crawler. You have a few options: Explicitly declare the return type for each crawler, e.g., CheerioCrawler or PlaywrightCrawler. Use BasicCrawler to cover multiple types. Use a type cast to bypass TypeScript’s strict type checking, though this is less safe. Basically, there’s no one-size-fits-all type, so you need to choose the approach that works best for your interface.
n
k get it, thanks a lot!
3 Views